//Given an integer array nums and an integer k, return the kᵗʰ largest element 
//in the array. 
//
// Note that it is the kᵗʰ largest element in the sorted order, not the kᵗʰ 
//distinct element. 
//
// 
// Example 1: 
// Input: nums = [3,2,1,5,6,4], k = 2
//Output: 5
// Example 2: 
// Input: nums = [3,2,3,1,2,4,5,5,6], k = 4
//Output: 4
// 
// 
// Constraints: 
//
// 
// 1 <= k <= nums.length <= 10⁴ 
// -10⁴ <= nums[i] <= 10⁴ 
// 
// Related Topics Array Divide and Conquer Sorting Heap (Priority Queue) 
//Quickselect 👍 7077 👎 410


package leetcode.editor.en;

import java.util.Comparator;
import java.util.PriorityQueue;

public class _215_KthLargestElementInAnArray {
    public static void main(String[] args) {
        Solution solution = new _215_KthLargestElementInAnArray().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int findKthLargest(int[] nums, int k) {

            PriorityQueue<Integer> pq = new PriorityQueue<>(Comparator.comparing(v1->v1, Comparator.reverseOrder()));
            for (int num : nums) {
                pq.offer(num);
            }
            for (int i = 1; i < k; i++) {
                pq.poll();
            }
            return pq.poll();
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}